//201902104047 周润恺
package cn.edu.sdjzu.xg.bysj.service;

import cn.edu.sdjzu.xg.bysj.dao.ProfTitleDao;
import cn.edu.sdjzu.xg.bysj.domain.ProfTitle;
import util.Condition;
import util.JdbcHelper;
import util.Pagination;

import java.sql.Connection;
import java.sql.JDBCType;
import java.sql.SQLException;
import java.util.Collection;

public final class ProfTitleService {
	private static ProfTitleDao profTitleDao= ProfTitleDao.getInstance();
	private static ProfTitleService profTitleService=new ProfTitleService();
	private ProfTitleService(){}

	public static ProfTitleService getInstance(){
		return profTitleService;
	}

	/**
	 * 向profTitleDao发消息根据条件和分页查找元组
	 * @param condition
	 * @param pagination
	 * @return
	 * @throws SQLException
	 */
	public Collection<ProfTitle> findAll(Collection<Condition> condition, Pagination pagination) throws SQLException {
		Connection connection = JdbcHelper.getConn();
		Collection<ProfTitle> profTitles = profTitleDao.findAll(connection,condition,pagination);
		JdbcHelper.close(connection);
		return profTitles;
	}

	/**
	 * 向profTitleDao发消息根据id查找
	 * @param id
	 * @return
	 * @throws SQLException
	 */
	public ProfTitle find(Integer id) throws SQLException {
		Connection connection = JdbcHelper.getConn();
		ProfTitle profTitle = profTitleDao.find(connection,id);
		JdbcHelper.close(connection);
		return profTitle;
	}

	/**
	 * 向profTitleDao发消息更新
	 * @param updatedProfTitle
	 * @return
	 * @throws SQLException
	 */
	public boolean update(ProfTitle updatedProfTitle) throws SQLException {
		Connection connection = JdbcHelper.getConn();
		boolean updated = profTitleDao.update(connection,updatedProfTitle);
		JdbcHelper.close(connection);
		return updated;
	}

	/**
	 * 向profTitleDao发消息添加
	 * @param addedProfTitle
	 * @return
	 * @throws SQLException
	 */
	public boolean add(ProfTitle addedProfTitle) throws SQLException {
		Connection connection = JdbcHelper.getConn();
		boolean added = profTitleDao.add(connection,addedProfTitle);
		JdbcHelper.close(connection);
		return added;
	}

	/**
	 * 向profTitleDao发消息删除
	 * @param id
	 * @return
	 * @throws SQLException
	 */
	public boolean delete(Integer id) throws SQLException {
		Connection connection = JdbcHelper.getConn();
		boolean deleted = profTitleDao.delete(connection,id);
		JdbcHelper.close(connection);
		return deleted;
	}
}

